package com.sangeng.controller;

import com.sangeng.domain.core.ResponseResult;
import com.sangeng.domain.dto.ArticleInsertDto;
import com.sangeng.domain.dto.ArticleListDto;
import com.sangeng.domain.dto.ArticleListQueryDto;
import com.sangeng.domain.dto.ArticleUpdateDto;
import com.sangeng.domain.entity.Article;
import com.sangeng.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;
    @PostMapping
    public ResponseResult insertArticle(@RequestBody ArticleInsertDto insertArticle) {
        return articleService.insertArticle(insertArticle);
    }

    @GetMapping("/list")
    public ResponseResult articleList(ArticleListQueryDto articleListDto) {
        return articleService.adminArticleList(articleListDto);
    }

    @GetMapping("/{id}")
    public ResponseResult getArticleDetialsById(@PathVariable Long id) {
        return articleService.getAdminArticleById(id);
    }

    @PutMapping
    public ResponseResult updateArticle(@RequestBody ArticleUpdateDto article) {
        return articleService.updateArticle(article);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteArticle(@PathVariable Long id) {
        return articleService.deleteById(id);
    }

}
